$(function (){

$('._view_checked').click(function (){
  var obj = $(this);
  var checked_status = obj.is(':checked');
  var checked_value = obj.val();

  if(checked_status==true){
    //选中
    $('#view_tr_'+checked_value).show();
  }else{
    //非选中
    $('#view_tr_'+checked_value).hide();
  }

});

//类型
$('._dropdown_menu').click(function (){
  var obj = $(this);
  var key = obj.attr('data-key');
  var value = obj.attr('data-value');
  
  //当前页面值
  $('._view_type_b_'+key).html(value);
  //预览中值
  $('#view_type_'+key).html(value);
});

//说明介绍
$('._view_desc').blur(function (){
  var obj = $(this);
  var text = obj.val();
  var key = obj.attr('data-key');

  if(text!='' || text !='undefined'){
    $('#view_desc_'+key).html(text);
  }
});

$("._fields_submit").click(function (){
  var data = getdata();
  var new_data = {};
  new_data.data = data;
  new_data.id = $('._file_id').val();
//console.log(data);

  //ajax请求
  $.ajax({
    url:'/Structure/ajaxFilefield.html',
      type:'POST',
      dataType:'json',
      async:true,
      data:new_data,
      success:function (req){
        if(req.status==200){
          location.href="/Structure/index.html";
        }else{
          alert(req.msg);
        }
        return;
      }
  });

});


});

//获取字段信息数据
function getdata(){
  var data = {};
  $('._view_checked').each(function (){
      var obj = $(this);
      var checked_status = obj.is(':checked');
      var checked_value = obj.val();

      var name = $('.init_name_'+checked_value).text();
      var type = $('._view_type_b_'+checked_value).text();
      var desc = $('._init_desc_'+checked_value).val();

      
      if(checked_status==true){
        data[checked_value] = [];
        data[checked_value].push(name);
        data[checked_value].push(type);
        data[checked_value].push(desc);
      }
      
  });

  return data;
}
